var tc, al;
layui.use(['element', 'form', 'layedit', 'laydate', 'table'], function () {
    var element = layui.element,
        form = layui.form,
        layer = layui.layer,
        layedit = layui.layedit,
        table = layui.table,
        $ = layui.jquery,
        laydate = layui.laydate;
    tc = function tc(a) {
        layer.msg(a, {
            offset: 'auto',
            anim: 6
        });
    };
    al = function al(t) {
        layer.alert(t, {
            skin: 'layui-layer-molv' //样式类名
                ,
            closeBtn: 0
        })
    };
})

function encode(a) {
    var key = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=";
    var arr = a.split(""),
        le = 30 - a.length,
        s = [],
        str = "";
    if (a.length < 10) {
        s.push(0);
        s.push(a.length)
    } else {
        s.push((a.length + "").split("")[0])
        s.push((a.length + "").split("")[1])
    }
    for (var i = 0; i < le; i++) {
        s.push(key[Math.floor(Math.random() * 64)])
    }
    for (var j = 0; j < 32 - a.length; j++) {
        if (j < a.length) {
            str += arr[j];
            str += s[j]
        } else {
            str += s[j]
        }
    }
    return str;
}
var ll = new Vue({
    el: "#login",
    data: {
        usernum: "",
        userpass: "",
        code: "",
        codeurl: "../member/sendsms.do",
        loginurl: "../member/doaction.do",
        wait: 60,
        codedisabled: !1,
        postdisabled: !1,
        str: /\登录成功!/g
    },
    methods: {
        sendAuthenticationCode: function sendAuthenticationCode() {
            var _this = this;
            if (this.usernum) {
                this.$http.post(this.codeurl, {
                    enews: "login",
                    MerchantId: this.usernum
                }, {
                    emulateJSON: true
                }).then(function (result) {
                    if (result.body.msg_code === "0000") {
                        tc(result.body.msg);
                    } else {
                        var t = "错误代码：" + result.body.msg_code + "," + result.body.msg;
                        al(t)
                    }
                });
            } else {
                tc("请输入商户号");
            }
        },
        login: function login() {
            var _this2 = this;
            if (this.usernum && this.userpass) {
                var str4 = /^[A-Za-z0-9]+$/g;
                if (!str4.test(this.usernum)) {
                    al("输入错误，用户名只能为数字或字母，请检查")
                } else {
                    this.$http.post(this.loginurl, {
                        enews: "login",
                        tobind: '0',
                        username: this.usernum,
                        ud: encode(this.userpass),
                        lifetime: 0,
                        key: this.code
                    }, {
                        emulateJSON: true
                    }).then(function (result) {
                        if (result.body.msg_code === "0000") {
                            sessionStorage.setItem("userid", _this2.usernum);
                            window.location.href = "index.html";
                        } else {
                            // var s = /\您的用户名或密码有误!/g;
                            // if (s.test(result.body)) {
                            //     tc("用户名或密码错误");
                            // } else {
                            var t = "错误代码：" + result.body.msg_code + "," + result.body.msg;
                            al(t)
                            // }
                        }
                    });
                }
            } else {
                tc("用户名或密码不能为空");
            }
        }
    }

});